﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AISFMIOperator
{
    public partial class AddCompanyForm : Form
    {
        public AddCompanyForm()
        {
            InitializeComponent();
            RefreshAllData();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Address a = new Address();
            a.AddressID = 0;
            a.Addr = addresstextBox3.Text.Trim();
            a.City = (City)citycomboBox1.SelectedItem;
            a.PostIndex = int.Parse(postindextextBox4.Text.Trim());

            a.Save();

            Company c = new Company();
            c.CompanyID = 0;
            c.INN = inntextBox2.Text.Trim();
            c.CompanyName = nametextBox1.Text.Trim();
            c.ContactPhone = phonetextBox6.Text.Trim();
            c.Email = emailtextBox5.Text.Trim();
            c.Address = a;

            c.Save();

            this.Close();

        }

        private void RefreshAllData()
        {
            this.citycomboBox1.DataSource = City.GetAllCities();
            this.citycomboBox1.DisplayMember = "CityFullName";
        }

        private void AddCompanyForm_Load(object sender, EventArgs e)
        {

        }
    }
}
